<template>
  <div>
    <!-- 头部返回按钮 -->
     <div class="header">
          <div class="text" @click="okk">
          <i class="iconfont icon-back"></i>
          <span class="text1">
            <i class="iconfont icon-fanhui"></i>
            发布服务
            </span>
       </div>
   </div>

   <mt-field label="经验" placeholder="请输入经验" v-model="form.experience"></mt-field>
   <mt-field label="擅长" placeholder="请输入擅长" v-model="form.specialty"></mt-field>
   <mt-field label="价格" placeholder="请输入价格" v-model="form.price"></mt-field>
   <mt-field label="上门时间" placeholder="请输入上门时间" v-model="form.door_time"></mt-field>
        <!-- 上传头像 -->
    <div class="portrait">
      <span class="details">
        <div class="right">请上传头像</div>
        <el-upload
            class="avatar-uploader"
            action="http://localhost:7001/uploadUser"
            :show-file-list="false"
            :on-success="handleAvatarSuccess"

            >
            <img v-if="imageUrl" :src="imageUrl" class="avatar">
            <i v-else class="el-icon-plus avatar-uploader-icon"></i>
          </el-upload>
      </span>
    </div>
      <!-- <div class="icon" @click="changeAvatar"> </div> -->

   <!--点击确定 -->
    <div class="confirmButton">
        <mt-button class="but" type="plain" size="large" @click="toAdd">确认</mt-button>
    </div>

  </div>
</template>

<script>
import { Toast } from 'mint-ui'
export default {
  data () {
    return {
      imageUrl: '',
      form: {
        user_id: this.$store.getters['user/id'],
        experience: '',
        price: '',
        door_time: '',
        specialty: '',
        top_img: '',
        status: 1
      }
    }
  },
  methods: {
    okk () {
      this.$router.go(-1)// 返回上一层
    },
    yes () {
      console.log('111111111')
    },
    handleAvatarSuccess (response, file, fileList) {
      const url = 'http://localhost:7001' + file.response.url
      console.log(url)
      this.imageUrl = url
      this.form.top_img = url
    },
    toAdd () {
      this.$http({
        url: '/addRelease', // 请求地址
        method: 'post', // 设置请求方式
        data: this.form // 把注册参数放进请求中
      })
        .then(e => {
          // 处理请求返回的结果
          // console.log(e.data)
          if (e.data.code === '1') {
            Toast({
              message: '发布成功',
              position: 'middle',
              duration: 3000
            })
            this.$router.go(-1)// 返回上一层
          } else {
            Toast({
              message: '发布失败',
              position: 'middle',
              duration: 3000
            })
          }
        })
        .catch(e => {
          // 处理请求发生的异常
          console.log(e)
        })
    }
  }
}
</script>

<style scoped>
.header {
  height: 1.5rem;
  width: 100%;
  background:#96D596;
}
.text{
  padding-top:4%;
  font-size:0.55rem;
  color:white
}
.iconfont{
  font-size: 0.55rem;
}
.confirmButton{
  display: flex;
  justify-content: center;
  width:90%;
  margin: 0.5rem;
  background: #96D596;
  color:azure
}
.confirmButton .but{
  background: #96D596;
}

.portrait{
  margin-top:10px;
  padding-bottom:10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid #ccc;
}

.portrait .details{
  padding-left:20px;
}
.portrait .right{
  margin-right:20px;;
}

/* 上传头像 */
  .avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }
  .avatar {
    width: 78px;
    height: 78px;
    border-radius: 6px;
  }

  /* 上传头像 */
  .avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    border-radius:50px;
    margin-right: 20px;
    width:50px;
    height: 50px;
    text-align: center;
    margin-top:10px;
  }
  .avatar {
    width: 98px;
    height: 98px;
    border-radius: 6px;
    margin-left: 10px;
    /* display: block; */
  }

</style>
